/*
    This header contains an extra data structure to store various configuration parameters
    the controls the behavior of CCD readout electronics.
   */

#include "COMMON.h"

#ifndef _CCD290_DRV_CONFIG_H_
#define _CCD290_DRV_CONFIG_H_


/**************
 *  CCD290
 * ***********/

/* number of parameters needed to fully describe CCD290 drive signal */

// #define CCD290_DRV_CONFIG_PARAM_NUM 26  // @2024-08-20:增加参数ddr_data_rdy_cnt_max
/*#define CCD290_DRV_CONFIG_PARAM_NUM 27  // @2024-08-20:增加参数ddr_data_rdy_cnt_max*/
#define CCD290_DRV_CONFIG_PARAM_NUM 29  // @2024-08-20:增加参数ddr_data_rdy_cnt_max


typedef struct ccd290_drive_config_{
    
    //  [VTRANS]
    int vtrans_num;         // 垂直转移行数
    int vtrans_skip_num;    // 开始读出时丢弃的转移行数
    
    //  [HTRANS]
    int htrans_num;         // 水平转移次数（即一行的像元数）

    //  [VTRANS]
    int imgCLK1_cnt_min, imgCLK1_cnt_max;
    int imgCLK2_cnt_min, imgCLK2_cnt_max;
    int imgCLK3_cnt_min, imgCLK3_cnt_max;
    int imgCLK4_cnt_min, imgCLK4_cnt_max;
    int imgCLKx_cnt_MAX;
    int vtrans_state_cnt_max;   // 由clk_reg驱动

    int ddr_data_rdy_cnt_max;   // 控制ddr_data_rdy信号拉高的时间,同样由clk_reg驱动,最小值可以为0

    int bias_ctr_cnt_min, bias_ctr_cnt_max;

    //  [HTRANS]
    int phi1_cnt_min, phi1_cnt_max;
    int phi2_cnt_min, phi2_cnt_max;
    int phi3_cnt_min, phi3_cnt_max;
    int rst_cnt_min, rst_cnt_max;

    //  [DELAY_CTRL]
    int delay_sel;
    int ddr_addr_sel;
    int sample_cnt_min;

    int VB_cnt_min;
    int VB_cnt_max;

    char config_file[1024]; // name of the configuration file
} ccd290_drive_config;

int load_ccd290_drive_config_params(   char *cfg_fname, 
                                       ccd290_drive_config *cfg );

int copy_ccd290_drive_config_params(   ccd290_drive_config *cfg_src, 
                                       ccd290_drive_config *cfg_dest );

int extract_ccd290_drive_config_params( ccd290_drive_config *cfg, 
                                        uint *reg_vals );

int print_ccd290_drive_config_params( ccd290_drive_config *cfg_src );

int free_ccd290_drive_config_params( ccd290_drive_config *cfg_src );


int get_scan_param_from_ini( char *ini_file, int *skip_num, int *trans_num );

#endif // _CCD290_DRV_CONFIG_H_
